package com.zzyl.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.BedDto;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.naming.Name;
import java.util.List;

@RestController
@RequestMapping("/bed")
@Api(tags = "床位管理相关接口")
public class BedController extends BaseController {

    @Autowired
    private BedService bedService;

    @GetMapping("/read/room/{roomId}")
    @ApiOperation(value = "根据房间id查询床位", notes = "传入房间id")
    public ResponseResult<List<BedVo>> readBedByRoomId(
            @ApiParam(value = "房间ID", required = true) @PathVariable("roomId") Long roomId) {
        List<BedVo> beds = bedService.getBedsByRoomId(roomId);
        return success(beds);
    }


    @PostMapping("/create")
    @ApiOperation(value = "添加床位",notes = "添加床位信息")
    @ApiOperationSupport(includeParameters = {"bedDto.bedNumber","bedDto.sort","bedDto.roomId"})
    //name="bedDto",  设置参数名表示对这个参数描述，不可以随意些，要与参数对象名相同
    // value = "床位信息对象",  设置中文别名
    // required = true,    参数不能为空
    // dataType = "BedDto"      设置参数所属类型
//    @ApiImplicitParam(name="bedDto",value = "床位信息对象",required = true,dataType = "BedDto")
    public ResponseResult addBed(@ApiParam(value = "床位信息对象",required = true)@RequestBody BedDto bedDto){
        logger.info("处理床位添加，参数为{}"+bedDto);
        bedService.addBed(bedDto);
        return success();
    }

    @GetMapping("/read/{id}")
    @ApiOperation("根据id查询床位")
    @ApiOperationSupport(includeParameters = {"id"})
    public ResponseResult getBedById(@ApiParam(value = "Id",required = true)@PathVariable Long id){
        logger.info("根据id查询床位,请求参数为{}"+id);
        BedVo bedVo = bedService.getBedById(id);
        return success(bedVo);
    }

    @PutMapping("/update")
    @ApiOperation("更改床位")
    @ApiOperationSupport(includeParameters = {"bedDto.bedNumber","bedDto.sort","bedDto.id","bedDto.roomId"})
    public ResponseResult updateBed(@ApiParam(value = "床位修改参数",required = true)@RequestBody BedDto bedDto){
        logger.info("修改床位,参数为{}"+bedDto);
        bedService.update(bedDto);
        return success();
    }


    @DeleteMapping("/delete/{id}")
    @ApiOperation("根据床位id删除床位")
    @ApiOperationSupport(includeParameters = {"id"})
    public ResponseResult deleteBedById(@ApiParam(value = "Id",required = true)@PathVariable Long id){
        logger.info("根据床位id删除床位,参数为"+id);
        bedService.delete(id);
        return success();
    }







}
